package org.wattdepot.cli.command;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.wattdepot.cli.processor.CommandLineInterface;
import org.wattdepot.cli.processor.SensorDataCommand;

/**
 * Test for the SensorDataTime command.
 * 
 * @author Kendyll Doi
 * @author Kimberly Heu
 *
 */
public class TestSensorDataTimeCommand extends CommandLineInterface {
  
  /**
   * Tests the SensorDataTime methods. 
   * @throws Exception If problems occur. 
   */
  @Test
  public void testSensorDataCommand() throws Exception {
    
    List<String> commandList = new ArrayList<String>(); // List of commands
    
    commandList.add("sensordata");
    commandList.add("SIM_WAIAU_7");
    commandList.add("timestamp");
    commandList.add("2009-11-15T02:00:00.000-10:00");
    
    SensorDataCommand command = new SensorDataCommand(); // command
    
    // The result from executing the individual method
    String methodResult = 
      WattSensorDataTime.wattSensorDataTime("SIM_WAIAU_7", "2009-11-15T02:00:00.000-10:00", client);
    // The result from executing corresponding command
    String commandResult = command.doCommand(commandList);
    
    // Ensure answer is correct
    assertTrue("Checking method result", methodResult.contains("8.8E7"));
    // Ensure both results are correct
    assertEquals("Checking method and command results are equal", methodResult, commandResult);
  }
  
  /**
   * Test that the input to the command is validated.
   * 
   * @throws Exception if problem occurs
   */
  @Test
  public void testInputValidation() throws Exception {
    
    List<String> commandList = new ArrayList<String>();
    commandList.add("sensordata");
    commandList.add("NONEXISTANT");
    commandList.add("timestamp");
    commandList.add("2009-10-31T00:00:00.000-10:00");
    
    SensorDataCommand command = new SensorDataCommand();
    String commandResult = command.doCommand(commandList);
    
    // Test for an incorrect source
    /*
    System.out.println(commandResult);
    assertTrue("Checking invalid source", commandResult.startsWith("No data found"));
    */
    
    commandList.remove(1);
    commandList.add(1, "SIM_WAIAU_7");
    commandList.remove(2);
    commandList.add(2, "timeestamp");
    
    // Test for invalid use of "timestamp" argument
    commandResult = command.doCommand(commandList);
    assertTrue("Checking invalid format for command", commandResult.contains("Incorrect syntax"));
    
    // Test for too few arguments
    commandList.remove(3);
    commandResult = command.doCommand(commandList);
    assertTrue("Checking invalid number of commands", commandResult.contains("Incorrect number"));
  }
}
